#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Jul 31 19:28:54 2022

@author: jerry
"""
import os
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.ocr.v20181119 import ocr_client, models


try:
    cred = credential.Credential(
        os.environ.get("AKIDDG3btue7JEuKUO1OIvHMBk22lFSO3RYO"),
        os.environ.get("atwiDRQ8alfJfkfKiodBSSBeqkNkqeBR"))
    httpProfile = HttpProfile()
    httpProfile.endpoint = "ocr.tencentcloudapi.com"

    clientProfile = ClientProfile()
    clientProfile.httpProfile = httpProfile
    client = ocr_client.OcrClient(cred, "ap-shanghai", clientProfile)

    req = models.GeneralAccurateOCRRequest()
    req.ImageUrl = image_to_base64("/home/bishop/python/ocr/test1.png")
    resp = client.GeneralFastOCR(req)
    print(resp.to_json_string())

except TencentCloudSDKException as err:
    print(err)